package com.michale.admin.controller.common;

import com.michale.admin.controller.tool.BaseController;
import com.michale.common.result.AjaxResult;
import com.michale.common.utils.String.StringUtils;
import com.michale.framework.security.service.RegisterService;
import com.michale.system.service.ConfigService;
import com.michale.system.vo.register.RegisterBody;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Michale
 * @apiNote 注册管理
 */
@Api(tags = "注册管理")
@RestController
public class RegisterController extends BaseController {
    @Resource
    private ConfigService configService;
    @Resource
    private RegisterService registerService;

    /**
     * 注册用户
     *
     * @param registerBody
     * @return
     */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody registerBody) {
        if (!("true".equals(configService.selectConfigByKey("system.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(registerBody);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
